package com.zyk.leetcode;

import com.zyk.util.TreeUtil;

/**
 * @author zhangsan
 * @date 2021/4/13 8:56
 */
public class C783 {

    int ans, pre;

    public int minDiffInBST(TreeNode root) {
        ans = Integer.MAX_VALUE; pre = -1;
        process(root);
        return ans;
    }

    private void process(TreeNode root) {
        if (root == null) {
            return;
        }
        process(root.left);
        if (pre != -1) {
            ans = Math.min(ans, root.val - pre);
        }
        pre = root.val;
        process(root.right);
    }


    // for test
    public static void main(String[] args) {
        C783 test = new C783();

        Integer[] nums = {90, 69, null, 49, 89, null, 52};
        TreeNode root = TreeUtil.generateTreeByArr(nums);
        System.out.println(test.minDiffInBST(root));
    }

}
